package com.hm.health.Activity.ecg;

import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.hm.health.Activity.BaseActivity;
import com.hm.health.R;
import com.hm.health.adapter.EcgTestRecordAdapter;
import com.hm.health.entity.dao.EcgStatistics;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by chenshi on 2020/3/9.
 */

public class EcgHistorySummaryActivity extends BaseActivity {
    @BindView(R.id.rv_ecg_records)
    RecyclerView mRvEcgRecords;
    List<EcgStatistics> mEcgStatistics = new ArrayList<>();
    private EcgTestRecordAdapter mEcgTestRecordAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ecg_history_summary);
        ButterKnife.bind(this);
        setCenterTitle(getString(R.string.ecg_history_records));
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        mEcgTestRecordAdapter = new EcgTestRecordAdapter(mEcgStatistics, mContext);
        mRvEcgRecords.setAdapter(mEcgTestRecordAdapter);
        loadRecords();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    private void loadRecords() {
        List<EcgStatistics> ecgStatistics;
        ecgStatistics = DataSupport.order("mStartTime desc").find(EcgStatistics.class);
        if (null != ecgStatistics) {
            mEcgStatistics.addAll(ecgStatistics);
            mEcgTestRecordAdapter.notifyDataSetChanged();
        }
    }

}
